<template>
	<view class="">
		<uni-nav-bar :statusBar="true" leftIcon="back" title="实名认证" @clickLeft="$tab.back()" :border="false">
		</uni-nav-bar>

		<view class="text-gray font-700 text-28 p-16" v-if="verifyState!=1">
			为保证您的账户安全，请先完成实名认证
		</view>

		<view class="bg-FFF px-32 py-46" v-if="verifyState!=1">
	<!-- 		<view class="flex align-center justify-between">
				<view class="font-700 text-36 ">
					证件图片
				</view>
				<view class="text-869AFF text-28 font-700" @click="certificate = true">
					查看示例
				</view>
			</view>

			<view class="my-32 flex align-center justify-between">
						<view class="idCard flex align-center flex-col">
					<u-upload @afterRead="uploadFront" name="6" :multiple="false" :maxCount="1" width="250"
						height="150">
						<image :src="form.cardFront" mode="" style="width: 104px;height: 65px;">
						</image>
					</u-upload>

					<view class="text-28  font-700">
						身份证人像面
					</view>
				</view>
				<view class="idCard flex align-center flex-col">
					<u-upload @afterRead="uploadBack" name="6" :multiple="false" :maxCount="1" width="250" height="150">
						<image :src="form.cardBack" mode="" style="width: 104px;height: 65px;">
						</image>
					</u-upload>

					<view class="text-28  font-700">
						身份证国徽面
					</view>
				</view>
			</view> -->

			<view class="font-700 text-36 ">
				身份信息
			</view>

			<u--form labelPosition="left" :model="form" ref="form" labelWidth="75px">
				<u-form-item label="真实姓名" borderBottom ref="item1">
					<u--input v-model="form.realName" border="none" placeholder="请输入姓名" :adjustPosition="false">
					</u--input>
				</u-form-item>
				<u-form-item label="身份证号" borderBottom ref="item1">
					<u--input v-model="form.idCard" border="none" placeholder="请输入本人身份证号" :adjustPosition="false">
					</u--input>
				</u-form-item>
			</u--form>
		</view>
		<view class="" style="height: 50px;" v-if="verifyState!=1">
		</view>

		<u-modal :show="certificate" :title="'证件上传示例'" :closeOnClickOverlay="true" @confirm="certificate = false"
			@close="certificate = false">
			<view class="slot-content">
				<image src="https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/bg_shili.png"
					style="width: 268px;height: 225px;" mode=""></image>
			</view>
		</u-modal>

		<canvas canvas-id="imgCanvas" class="imgCanvas" />



		<!-- 支付方式选择 -->
		<view class="payWayPopup">
			<u-popup :show="payWayPopup" mode="center">
				<view class="box_1 text-center ">
					<view class="box_3" @click="payClose">
						<image src="https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/quxiao.png"
							style="width: 48rpx;" mode="widthFix"></image>
					</view>
					<view class="text-28 ">
						实名认证需支付小额费用
					</view>
					<view class="my-40">
						<view class="" v-for="(item,index) in payWayArr" :key="index">
							<view class="flex align-center justify-between py-32">
								<view class="flex align-center">
									<image :src="item.img" style="width: 48rpx;" mode="widthFix"></image>
									<view class="flex align-start flex-col ml-16">
										<view class="text-28  ">
											{{item.name}}
										</view>
									</view>
								</view>
								<image
									:src="item.checked ?'https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/xuanze.png' : 'https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/weixuanzhong.png'"
									style="width: 40rpx;" mode="widthFix" @click="paySelect(item)"></image>
							</view>
							<u-line color="#F2F2F2"></u-line>
						</view>
					</view>
					<u-button class="box_2" @click="confimPay">确认支付</u-button>
				</view>
			</u-popup>
		</view>

		<bottom-btn txt="确认" @click="submit"></bottom-btn>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: this.$store.getters.userInfo,
				verifyState: this.$store.getters.userInfo.verifyState,
				payWayPopup: false,
				form: {
					realName: "",
					idCard: "",
				},
				// cardFront: "https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/zhengmian.png",
				// cardBack: "https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/fanmian.png",
				certificate: false,
				payWayArr: [
					//#ifdef APP-PLUS || H5
					{
						name: "支付宝支付",
						img: "https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/zhifubaozhifu.png",
						checked: true
					},
					//#endif

					//#ifdef MP-WEIXIN
					{
						name: "微信支付",
						img: "https://file.fulewanjia.com/fulewanjia/profile/upload/2023/10/19/weixinzhifu_20231019113312A393.png",
						checked: true
					},
					//#endif
				],
			};
		},
		onLoad() {
			this.init();
			// validated 1 判断 已缴费 则实名认证不用再次交费
			// if (this.user.validated != 1) {
			// 	this.payWayPopup = true
			// }
		},
		onPullDownRefresh() {
			this.init();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			payClose() {
				this.payWayPopup = false
				this.$tab.back()
			},
			confimPay() {
				var that = this
				//#ifdef APP-PLUS || H5
				this.$Api.user.placeBusinesspay().then(res => {
					var orderInfo = res.data; //从服务器获取的订单
					this.$pay.Alipay(orderInfo).then(res => {
						this.$store.dispatch('GetInfo').then(() => {
							this.payWayPopup = false
							uni.$u.toast('支付成功')
						})
					}).catch(err => {
						uni.$u.toast('支付失败')
					})
				})
				// #endif

				// #ifdef MP-WEIXIN
				this.$api.home.businessWxpay().then(res => {
					let data = res.data
					console.log(data, 'data')
					this.$pay.WeChatPay(data)
				})
				// #endif

			},
			init() {
				this.form.realName = this.user && this.user.realName ? this.user.realName : "";
				this.form.idCard = this.user && this.user.idCard ? this.user.idCard : "";
				// this.form.cardFront = this.user && this.user.cardFront ? this.user.cardFront :
				// 	"https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/zhengmian.png";
				// this.form.cardBack = this.user && this.user.cardBack ? this.user.cardBack :
				// 	"https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/fanmian.png";
			},
			hideKeyboard() {
				uni.hideKeyboard()
			},
			//修好
			uploadFront(event, er) {
				let that = this;
				this.$Api.common.uploadFile(event.file.thumb).then(res => {
					that.form.cardFront = res.url;
				})
			},
			uploadBack(event, er) {
				let that = this;
				this.$Api.common.uploadFile(event.file.thumb).then(res => {
					that.form.cardBack = res.url;
				})
			},
			submit() {
				// if (this.form.cardFront === "" || this.form.cardFront ===
				// 	"https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/zhengmian.png") {
				// 	this.$modal.msgError("请上传身份证正面")
				// } else if (this.form.cardBack === "" || this.form.cardBack ===
				// 	"https://file.fulewanjia.com/fulewanjia/profile/preImages/mine/fanmian.png") {
				// 	this.$modal.msgError("请上传身份证反面")
				// } else 
				if (this.form.realName == "") {
					this.$modal.msgError("请输入真实姓名")
				} else if (this.form.idCard == "") {
					this.$modal.msgError("请输入身份证号")
				} else {
					this.$Api.user.realnameauthentication(this.form).then(response => {
						this.$store.dispatch('GetInfo').then(res => {
							uni.redirectTo({
								url: "/pages/mine/realPerson/state"
							})
						})
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.idCard {
		width: 48%;
		height: 160px;
		background: #F0F3FF;
		border-radius: 6px;
		padding: 24px 28px;
	}

	.imgCanvas {
		position: absolute;
		top: -100%;
		width: 100%;
		height: 100%;
	}
</style>
<style scoped lang="scss">
	/deep/ .u-modal__content {
		text-align: center;
	}

	.payWayPopup {
		.box_1 {
			width: 640rpx;
			border-radius: 24rpx;
			position: relative;
			padding: 32rpx;
			background: linear-gradient(to bottom, #F3CAB6 0%, #FEF8F1 18%);
		}

		.box_2 {
			width: 576rpx;
			height: 80rpx;
			background: #EA4B27;
			border-radius: 4rpx;
			line-height: 80rpx;
			color: #fff;
			font-size: 28rpx;
		}

		.box_3 {
			width: 80rpx;
			height: 80rpx;
			background: rgba(0, 0, 0, 0.3);
			position: absolute;
			right: 22rpx;
			top: 0;
			padding-top: 20rpx;
			border-radius: 0 0 40rpx 40rpx;
		}

		/deep/.u-popup__content {
			background-color: transparent;
		}
	}



	.shenhe {
		margin-top: 200rpx;
		padding-bottom: 48rpx;

		.t1 {
			margin-top: 32rpx;
			font-size: 40rpx;
			font-weight: 400;
			color: #333333;
			line-height: 40rpx;
		}

		.t2 {
			margin-top: 24rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #999999;
			line-height: 28rpx;
		}

		.t3 {
			font-size: 24rpx;
			font-weight: 400;
			color: #9E9E9E;
			line-height: 24rpx;
		}

		.t4 {
			color: #0650FF;
		}


		.zfb {
			width: 600rpx;
			height: 88rpx;
			background: #06B4FD !important;
			border-radius: 12rpx;
			margin-top: 48rpx;
			color: #fff;
		}
	}

	/deep/ .u-button {
		width: 364rpx !important;
		height: 84rpx !important;
		background: #FD212C !important;
		border-radius: 8rpx !important;
		color: #fff !important;
		border: none !important;
	}
</style>